package com.example.ygp.index;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ygp.entity.Course;
import com.example.ygp.entity.User;
import com.example.ygp.mapper.CourseMapper;
import com.example.ygp.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：ygp
 * @Package：com.example.ygp.index
 * @Project：db_demo1
 * @name：TestController
 * @Date：2023/12/23 19:20
 * @Filename：TestController
 */

@Slf4j
@RestController
public class TestController {

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/add")
    public String add() {
        Course course = new Course();
        for (int i = 0; i < 10; i++) {
            course.setCname("java_" + i);
//            course.setUserId(10l);
            course.setUserId(1l);
            course.setCstatus("normal");
            courseMapper.insert(course);
        }
        for (int i = 10; i < 20; i++) {
            course.setCname("java_" + i);
//            course.setUserId(10l);
            course.setUserId(2l);
            course.setCstatus("normal");
            courseMapper.insert(course);
        }

        return "add ok";
    }


    @RequestMapping(value = "/query")
    public Course query(@RequestParam(name = "cid") String cid) {
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
//        wrapper.eq("cid", 945396411778727936l);
        wrapper.eq("cid", Long.parseLong(cid));
        Course course = courseMapper.selectOne(wrapper);
        log.debug("{}", course);

        return course;
    }

    @RequestMapping(value = "/adduser")
    public String adduser() {
        User user = new User();
        for (int i = 0; i < 10; i++) {
            user.setUsername("username_" + i);
//            course.setUserId(10l);
            user.setUstatus("normal");
            userMapper.insert(user);
        }

        return "add user ok";
    }

    @RequestMapping(value = "/queryuser")
    public User queryuser(@RequestParam(name = "user_id") String user_id) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
//        wrapper.eq("cid", 945396411778727936l);
        wrapper.eq("user_id", Long.parseLong(user_id));
        User user = userMapper.selectOne(wrapper);
        log.debug("{}", user);

        return user;
    }


}
